package com.ruoyi.web.controller.house;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cost.service.IHouseCostTService;
import com.ruoyi.costQuery.domain.HouseCostT;
import com.ruoyi.costQuery.service.IHouseCostQueryTService;
import com.ruoyi.data.DataUtils;
import com.ruoyi.data.MD5;
import com.ruoyi.data.NumberData;
import com.ruoyi.door.domain.HouseDoorT;
import com.ruoyi.hisDoor.service.IHouseHisDoorService;
import com.ruoyi.purpose.service.IHousePurposeTService;
import com.ruoyi.setup.domain.HouseSetupT;
import com.ruoyi.setup.service.IHouseSetupTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 户管理Controller
 * 
 * @author lijie
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/house/hisDoor")
public class HouseHisDoorController extends BaseController
{
    @Autowired
    private IHouseHisDoorService houseHisDoorService;

    @Autowired
    private IHouseSetupTService houseSetupTService;
    /**
     * 缴费
     */
    @Log(title = "缴费管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult insertHisCost(@RequestBody HouseDoorT houseDoorT) throws Exception {
        houseDoorT.setCreater(getUsername());
        if(houseDoorT.getPapersCode()!=null){
            houseDoorT.setPapersCode(MD5.encrypt(houseDoorT.getPapersCode()));
        }
        if(houseDoorT.getUserName()!=null){
            houseDoorT.setUserName(MD5.encrypt(houseDoorT.getUserName()));
        }
        if(houseDoorT.getTel()!=null){
            houseDoorT.setTel(MD5.encrypt(houseDoorT.getTel()));
        }
        String FeeStandards = getFeeStandards();
        if ("1".equals(FeeStandards)){
            Double budgetMoney = DataUtils.multiplyTwo(houseDoorT.getPrice(),houseDoorT.getSpace());
            houseDoorT.setBudgetMoney(budgetMoney);
        }else if("2".equals(FeeStandards)){
            Double budgetMoney = DataUtils.saveTwoTruncation(houseDoorT.getPrice()*houseDoorT.getSpace());
            houseDoorT.setBudgetMoney(budgetMoney);
        } else if("4".equals(FeeStandards)){
            Double budgetMoney = DataUtils.saveOneTruncation(houseDoorT.getPrice()*houseDoorT.getSpace());
            houseDoorT.setBudgetMoney(budgetMoney);
        } else if("3".equals(FeeStandards)){
            Double budgetMoney = DataUtils.multiplyOne(houseDoorT.getPrice(),houseDoorT.getSpace());
            houseDoorT.setBudgetMoney(budgetMoney);
        } else if ("5".equals(FeeStandards)){
            Double budgetMoney = DataUtils.doubleFloor(houseDoorT.getPrice()*houseDoorT.getSpace());
            houseDoorT.setBudgetMoney(budgetMoney);
        } else {
            Double budgetMoney = DataUtils.intFloor(houseDoorT.getPrice()*houseDoorT.getSpace());
            houseDoorT.setBudgetMoney(budgetMoney);
        }
        int costId = houseHisDoorService.updateHouseHisDoorT(houseDoorT);
        HouseCostT houseCostVO = new HouseCostT();
        houseCostVO.setCostId(Long.valueOf(costId));
        return AjaxResult.success(houseCostVO);
    }

    public String getFeeStandards(){
        HouseSetupT houseSetupT = new HouseSetupT();
        HouseSetupT list = houseSetupTService.selectHouseSetupTByFeeStandards();
        return list.getFeeStandards();
    }
}
